home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / C / Comet2.1.3.cpt / Comet / net_utils.asm < prev    next >
Assembly Source File  |  1989-12-13  |  1KB  |  69 lines

  1. ;    Copyright Cornell University 1986.  All rights are reserved.
  2. ;
  3. ;    As of 4/10/86:
  4. ;
  5. ;   10/8/87 kevin replaced old cksum loop with a snazzy dbra loop
  6. ;    11/8/88 kevin made cksum loop faster by using 32 bit ops to hold carries
  7.  
  8.     public _version
  9.     _version: dcb.w 1,10
  10.  
  11. ; bswap(int) swaps the bytes in an int
  12.  
  13.     public    _swab
  14.     public    _bswap
  15.  
  16. _swab:
  17. _bswap:
  18.     move.b    4(a7),d0
  19.     move.b    5(a7),d1
  20.     lsl        #8,d1
  21.     or.w    d1,d0
  22.     rts
  23.  
  24. ;
  25. ; _cksum(buf, len) performs an Internet type checksum. buf points to where
  26. ;     the checksumming should begin, len is the number of 16 bit words
  27. ;    to be summed. Returns the checksum. This is the Unix compatible
  28. ;   version
  29. ;
  30.     public    _cksum
  31.  
  32. _cksum:
  33.     move.l    4(a7),a0        ; a0 -> buffer
  34.     clr.l    d0                ; d0 -> initial value for xsum
  35.     clr.l    d2                ; d2 = 0
  36.     move.w    8(a7),d1        ; d1 -> length
  37.     bra        start            ; jump to dbra to start loop
  38.  
  39. lpchk:
  40.     move.w    (a0)+,d2        d2 -> next word
  41.     add.l    d2,d0            d0 += d2
  42. start:
  43.     dbra    d1,lpchk        ;loop around
  44.  
  45. lpdone:
  46.     swap    d0                ; switch so carries on bottom
  47.     move.w    d0,d1
  48.     swap    d0
  49.     add.w    d1,d0            ; add carries back in
  50.     bcc.s    no_carry
  51.     addq.w    #1,d0            ; yet another carry occurred
  52.  
  53. no_carry:
  54.  
  55.     rts                        ; all done
  56.  
  57.  
  58.  
  59.  
  60. ; byte swap a long
  61.  
  62.     public    _lswap
  63.     public    _wswap
  64. _lswap:
  65. _wswap:
  66.     move.l    4(a7),d0
  67.     swap    d0
  68.     rts
  69.